package com.dunshan.dunshanfile.controller;

import com.dunshan.dunshanfile.pojo.PostFile;
import com.dunshan.md.Md5Encrypt;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * @author dunshan
 * @program: dunshan-pef
 * @description: 日志请求
 * @date 2021-11-10 23:41:36
 */
@Log4j2
@RestController
public class LogController {

    @GetMapping("/tag")
    public Object tagMdcInfo(String tiaoshi) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("data", "调试！");
        map.put("ok", tiaoshi);
        log.info("调试。。{}", tiaoshi);
        return map;
    }

    @GetMapping("/tag/1")
    public Object tagMdcInfoYce() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("data", "调试！");
        log.info("压测。。");
        return map;
    }

    @PostMapping("/NVPair")
    public Object NVPairPost(@RequestBody PostFile name) {
        log.info("请求结果 {}", name.getName());
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg", "调试！");
        map.put("fileName", name.getFile().getName());
        map.put("data", name.getName());
//        File fie = new File("/Users/liwen406/Desktop/file7d.har");
        return map;
    }

    @GetMapping("/pwd")
    public Object getPwd(String passWord, String salt) {
        String s = Md5Encrypt.encryptToMD5(passWord, salt);
        return s;
    }


    @GetMapping("/pwdWord")
    public Object getPwdWord(String passWord) {
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, Object> result = new HashMap<>();
        result.put("pwd", passWord);
        result.put("info", "7DGroup 工具专栏学习案例");
        result.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        map.put("data", result);
        return map;
    }

}
